package cn.openea.perpartner.growth.controller;


import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.growth.entity.GrowthRecord;
import cn.openea.perpartner.growth.service.IGrowthRecordService;
import cn.openea.perpartner.growth.service.IGrowthUserGradeService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * (GrowthConfig)表控制层
 *
 * @author makejava
 * @since 2022-08-09 11:12:57
 */
@RestController
@RequestMapping("growth")
public class GrowthController extends BaseController {
    @Autowired
    private IGrowthUserGradeService userGradeService;
    @Autowired
    private IGrowthRecordService recordService;

    @PostMapping("/grade")
    public AjaxResult queryUserGrade(String userId){
        JSONObject userGrade = userGradeService.selectUserGrade(userId);
        return AjaxResult.success("操作成功！",userGrade);
    }


    @PostMapping("/list")
    public TableDataInfo selectList(String userId) throws Exception {
        startPage();
        List<GrowthRecord> list = recordService.selectList(userId);
        return getDataTable(list);
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody GrowthRecord record)
            throws IllegalAccessException, InstantiationException {
        boolean flag = recordService.add(record);
        return  flag?AjaxResult.success():AjaxResult.error();
    }

}

